import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import qiankun from 'vite-plugin-qiankun';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  const appCode = env.VITE_APPCODE;

  return {
    base: env.VITE_BUILD_BASE_URL + appCode,
    plugins: [
      vue(),
      vueJsx(),
      qiankun(appCode, {
        useDevMode: true, // vite写法，webpack写法请查看对应文档
      }),
      tailwindcss(),
    ],
    server: {
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
        'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
        'Access-Control-Allow-Credentials': 'true',
      },
      proxy: {
        '^/api': {
          target: 'http://127.0.0.1:8888',
          changeOrigin: true,
        },
      },
    },
    resolve: {
      alias: {
        '@/': fileURLToPath(new URL('./src/', import.meta.url)),
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
    },
  };
});
